package com.base

import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.event.MessageEvent
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe

abstract class BaseActivity<T : ViewBinding> : AppCompatActivity() {
    lateinit var binding: T
    lateinit var context: Context
    val dataCenter = DataCenter.instance
    val deviceCenter = DeviceCenter.instance
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        context = this
        binding = getViewBinding()
        setContentView(binding.root)
        createView()
        EventBus.getDefault().register(this)
    }


    override fun onDestroy() {
        EventBus.getDefault().unregister(this)
        super.onDestroy()

    }
    @Subscribe
    fun onMessageEvent(event: MessageEvent) {}
    abstract fun getViewBinding(): T
    abstract fun createView()
}